define([], function() {

var requestAnimationFrame =
    window.requestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.msRequestAnimationFrame;

function Loop() {
  this.passes_ = [];
};

Loop.prototype.addPass = function(pass) {
  this.passes_.push(pass);
};

Loop.prototype.start = function() {
  requestAnimationFrame(this.onAnimationFrame_.bind(this));
};

Loop.prototype.onAnimationFrame_ = function() {
  var currentTime = (new Date()).getTime();
  if (!this.lastFrameTime_) {
    this.lastFrameTime_ = currentTime - (1000 / 60);
  }
  var timeDeltaMillis = currentTime - this.lastFrameTime_;
  this.lastFrameTime_ = currentTime;

  // window.console.log(timeDeltaMillis);

  for (var i = 0; i < this.passes_.length; i++) {
    this.passes_[i].execute(timeDeltaMillis);
  }

  requestAnimationFrame(this.onAnimationFrame_.bind(this));
};

return Loop;

});
